Repository navigation
🧪 test: restore inherited PYTHONPATH in native env-files test - #365
gaborbernat merged 4 commits into
Conversation
pytest-dev#290 made test_native_env_files_override_ini forward the caller's PYTHONPATH to its pytest subprocess; the rewrite in pytest-dev#308 dropped it again, so the subprocess can't import pytest_env.plugin when the plugin is only reachable through PYTHONPATH, and all 24 cases fail. Prepend the caller's PYTHONPATH to the scenario's value; with PYTHONPATH unset the subprocess environment is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simplint's conditional-in-test rule rejects the conditional dict unpacking. Always set PYTHONPATH to the joined value instead: pytester's popen rebuilds PYTHONPATH with filter(None, ...), which drops an empty value, so the case without an inherited PYTHONPATH is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The news check needs a fragment or the skip news label, which only maintainers can apply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
N7766
left a comment
There was a problem hiding this comment.
The absolute-path fix works with an unpacked wheel and no installed plugin. One inherited-path case remains on b972310: PYTHONPATH=unpacked lets the parent import pytest_env, but pytester changes cwd before its child resolves that relative entry.
# cwd contains unpacked/, extracted from the built wheel
PYTHONPATH="$PWD/unpacked" PYTEST_PLUGINS=pytest_env.plugin python -m pytest \
../pytest-env-pr365/tests/test_env.py -k test_native_env_files_override_ini -q
# 24 passed
PYTHONPATH=unpacked PYTEST_PLUGINS=pytest_env.plugin python -m pytest \
../pytest-env-pr365/tests/test_env.py -k test_native_env_files_override_ini -q
# 24 failed: child cannot import pytest_env.pluginShould relative entries be resolved against the original invocation directory before forwarding? This also fails on base; it is an uncovered case, not a new regression. AI-assisted reproduction on macOS/pytest 9.2.
|
It looks like #308 broke passing through I tried to propose a PR similar to this one that would restore passing through I can deal with this for now by manually cleaning |
|
@musicinmybrain I reproduced the plugin This test-only adjustment before python_env = dict(python_env)
if "PYTHONDONTWRITEBYTECODE" in os.environ:
python_env.setdefault("PYTHONDONTWRITEBYTECODE", os.environ["PYTHONDONTWRITEBYTECODE"])
expected_python = (expected_python[0], python_env.get("PYTHONDONTWRITEBYTECODE"))Both ambient-unset and ambient- |
#290 made
test_native_env_files_override_iniforward the caller'sPYTHONPATHto its pytest subprocess, so packagers who reachpytest-envonly throughPYTHONPATHcan run it. The parametrization rewrite in #308 (640b2b9) dropped that again: the test clears the environment and passes only the scenario's ownPYTHONPATH, so the subprocess can't importpytest_env.pluginand all 24 cases fail:We hit it packaging 1.8.8 for Debian, where pybuild runs the suite against the built wheel through
PYTHONPATH.The test now prepends the caller's
PYTHONPATH, if set, to the scenario's value. WhenPYTHONPATHis unset, as under tox, the value is an empty string, which pytester drops when it builds the subprocess'sPYTHONPATH(filter(None, ...)inPytester.popen), so the subprocess environment is unchanged; the unset scenarios still see nopythonpath_markerand the set ones still see it.A comment on that line now records why the caller's value is kept, so a later rewrite doesn't drop it again the way #308 did.
This changes only a test, so there's no new test. I added a
packagingnews fragment because I can't apply theskip newslabel; feel free to drop it and use the label instead, as in #290.Checked on Debian sid (Python 3.14.10, pytest 9.1.1, python-dotenv 1.2.1, pytest-mock 3.15.1), full suite:
mainPYTHONPATHonly (built wheel unpacked)PYTHONPATHunsetThe 24 failures on
mainare alltest_native_env_files_override_ini. The same change, carried as a Debian patch on 1.8.8, also passes the Debian build on Python 3.14 and 3.15.ruff0.17.5 (format and check) andsimplint0.14.2, the versions pinned in.pre-commit-config.yaml, pass; I haven't run the otherprekhooks.